package cn.t222.controller.sys;

import cn.t222.pojo.Result;
import cn.t222.pojo.SysResources;
import cn.t222.service.ResourceService;
import cn.t222.util.LayuiUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.List;

@RestController
@Slf4j
public class ButtonPermissionController {
    @Resource
    private ResourceService resourceService;

    @GetMapping("/btn/html")
    public Result getResources(Principal principal, String modulePath) {
        String username = principal.getName();
        List<SysResources> list = resourceService.getAllButtonPermissions(username, modulePath);
        String btnHtml = LayuiUtil.getButtonHtml(list);
        if(log.isDebugEnabled()) {
            log.debug("modulePath:{}, btnHtml:{}", modulePath, btnHtml);
        }
        return Result.ok("200", "success", btnHtml);
    }
}
